﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyTimeLine.Controllers
{
    public class BaseController : Controller
    {
        public enum MessagesType
        {
            Error,
            Info,
            Success,
            Warning
        }

        public string TituloPagina { get; set; }

        public BaseController()
        {

            var titulo = "My Time Line";
            if (!string.IsNullOrWhiteSpace(TituloPagina))
            {
                titulo = string.Format("{0} - My Time Line", TituloPagina);
            }
            ViewBag.Title = titulo;
            ViewBag.GritterMessage = null;

        }


        public void ShowGritterMessage(string title, string message, MessagesType type, int? timer = 5000)
        {
            string statusImage;

            switch (type)
            {
                case MessagesType.Error:
                    statusImage = "error";
                    break;
                case MessagesType.Info:
                    statusImage = "info";
                    break;
                case MessagesType.Success:
                    statusImage = "success";
                    break;
                case MessagesType.Warning:
                    statusImage = "warning";
                    break;
                default:
                    statusImage = "important";
                    break;
            }

            string[] lista = (new string[]
                                  {
                                      title,
                                      message,
                                      statusImage,
                                      timer.ToString()
                                  });
            ViewBag.GritterMessage = string.Join(",", lista);
        }
        
    }
}
